package main

// 在没有编写客户端的时候如进行测试
// telnet localhost 9000

import (
    "bufio"
    "fmt"
    "log"
    "net"
)

func handle(conn net.Conn) {
    defer conn.Close() 

    scanner := bufio.NewScanner(conn)
    for scanner.Scan() {
        ln := scanner.Text()
        fmt.Println(ln)
        fmt.Printf("Type: %T\n", ln)
        ln = fmt.Sprint("FROM SERVER: " + ln)
        fmt.Fprintln(conn, ln)
    }
}

func main() {
    lin, err := net.Listen("tcp", ":9000")
    if err != nil {
        log.Fatalln(err)
    }
    defer lin.Close()

    for {
        conn, err := lin.Accept()
        if err != nil {
           log.Fatalln(err)
        }
        handle(conn)
    }
}
